import React from 'react';
import { useDispatch } from 'react-redux';
import { RouterProvider } from 'react-router-dom';
import { SnackbarProvider } from 'notistack';
import { loadTokenFromStorage } from '@/store/authSlice';
import router from '@/router/index';
import { NotificationProvider } from '@/context/NotificationContext';

function App() {
  const dispatch = useDispatch();

  React.useEffect(() => {
    dispatch(loadTokenFromStorage());
  }, [dispatch]);

  return (
    <NotificationProvider>
      <SnackbarProvider maxSnack={3}>
        <RouterProvider router={router} />
      </SnackbarProvider>
    </NotificationProvider>
  );
}

export default App;